﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using C.Entities;
using C.Unite;
using ChanExt;
using MySoft.Data;
using Newtonsoft.Json.Linq;

namespace ArtLand.OA.Project.AfterSale
{
    public partial class ASale_RePairList : CommonPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnNew.OnClientClick = Window1.GetShowReference("ASale_RePairChange.aspx","添加维修记录");
                BindGrid(GetWhere());
            }
        }


        #region BindGrid
        private void BindGrid(WhereClip wc)
        {
            Grid1.RecordCount = TbsDbSession.Default.From<AfSale_PrInfo>().Where(wc).Count();

            List<AfSale_PrInfo> items = TbsDbSession.Default.From<AfSale_PrInfo>().Where(wc).OrderBy(AfSale_PrInfo._.ID.Desc).Page(Grid1.PageSize, (Grid1.PageIndex + 1)).ToList();

            // 3.绑定到Grid
            Grid1.DataSource = items;
            Grid1.DataBind();
        }



        protected void Grid1_PageIndexChange(object sender, ChanExt.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid(GetWhere());
        }

        public WhereClip GetWhere()
        {
            WhereClip wc = WhereClip.All;
            //if (!string.IsNullOrEmpty(Request["did"]))
            //{
            //    wc = wc && Adm_BASICD._.BATYPE == int.Parse(Request["did"]);
            //}
            //if (!String.IsNullOrEmpty(ttbxMyBox2.Text))
            //{
            //    wc = wc && (Adm_BUDGET._.YERNUB.Contain(ttbxMyBox2.Text) || V_EmpInfo._.EMPLID.Contain(ttbxMyBox2.Text));
            //}
            return wc;
        }
        #endregion

        protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
        {
            e.Values[9] = "<a href=\"javascript:;\" onclick=\"window.open('/AfterSale/ASale_REPairPrint.aspx?id=" + e.Values[9] + "');\"><img src=\"/icon/printer.png\" /></a>";
            //e.Values[7] = "<a href=\"javascript:;\" onclick=\"TabView('/AfterSale/ASale_RePairChange.aspx?id=" + e.Values[7] + "', 'tab_wxadd', '修改维修记录', '/icon/comment_edit.png');\"><img src=\"/icon/comment_edit.png\" /></a>";
        }

        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            int id = int.Parse(Grid1.DataKeys[e.RowIndex][0].ToString());
            if (e.CommandName == "Del")
            {
                TbsDbSession.Default.Delete<AfSale_PrInfo>(AfSale_PrInfo._.ID == id);
                Alert.ShowInTop("删除成功！");
                BindGrid(GetWhere());
            }
        }
    }
}